package com.guigu.controller;

import com.guigu.entity.CheckitemBean;
import com.guigu.service.CheckitemService;
import com.guigu.vo.CheckitemBeanVO;
import com.guigu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
public class CheckitemController {

    @Autowired
    private CheckitemService checkitemService;

    @GetMapping("/index")
    public String index() {
        return "index";
    }

    @GetMapping("/findAll")
    public Result<List<CheckitemBean>> findAll() {

        List<CheckitemBean> CheckitemBeanList = this.checkitemService.selectCheckitem();

        System.out.println("检查项结果集："+CheckitemBeanList);

        return new Result<>("200", "true", "成功查询用户列表", CheckitemBeanList);
    }

    @PostMapping("/tjjcx")
    public Result tjjcx(@RequestBody CheckitemBeanVO checkitemBeanVO) {
        // 处理 POST 请求的逻辑代码
        System.out.println("添加中的form===="+checkitemBeanVO);

        String sex=checkitemBeanVO.getSex();

        if(sex.equals("")){
            sex="0";
        }

        System.out.println("sex===="+sex);

        CheckitemBean checkitemBean=new CheckitemBean(
                checkitemBeanVO.getId(),
                checkitemBeanVO.getCode(),
                checkitemBeanVO.getName(),
                sex,
                checkitemBeanVO.getAgexx()+"-"+checkitemBeanVO.getAgesx(),
                checkitemBeanVO.getPrice(),
                checkitemBeanVO.getType(),
                checkitemBeanVO.getAttention(),
                checkitemBeanVO.getRemark()

        );
        System.out.println("checkitemBean===="+checkitemBean);


        this.checkitemService.addcheckitem(checkitemBean);


        return new Result<>("200", "true", "添加成功", "添加成功");


    }

    @PostMapping("/xgjcx")
    public Result xgjcx(@RequestBody CheckitemBeanVO checkitemBeanVO) {
        // 处理 POST 请求的逻辑代码
        System.out.println("修改中的form===="+checkitemBeanVO);

        String sex=checkitemBeanVO.getSex();

        if(sex.equals("")){
            sex="0";
        }


        System.out.println("sex===="+sex);

        CheckitemBean checkitemBean=new CheckitemBean(
                checkitemBeanVO.getId(),
                checkitemBeanVO.getCode(),
                checkitemBeanVO.getName(),
                sex,
                checkitemBeanVO.getAgexx()+"-"+checkitemBeanVO.getAgesx(),
                checkitemBeanVO.getPrice(),
                checkitemBeanVO.getType(),
                checkitemBeanVO.getAttention(),
                checkitemBeanVO.getRemark()

        );
        System.out.println("checkitemBean===="+checkitemBean);


        this.checkitemService.updatecheckitem(checkitemBean);


        return new Result<>("200", "true", "修改成功", "修改成功");


    }

    @PostMapping("/scjcx")
    public Result scjcx(@RequestBody CheckitemBean checkitemBean ) {
        // 处理 POST 请求的逻辑代码

        System.out.println("对象：" + checkitemBean);

        this.checkitemService.deletecheckitemBeanByid(checkitemBean);

        return new Result<>("200", "true", "操作成功", "操作成功");
    }
}
